<!--  -->
<template>
    <div class="app-container">
        <div class="container">
            <el-row>
                <el-form :inline="true" :model="listQuery">
                    <el-form-item>
                        <el-button type="primary" @click="onSearch">查询</el-button>
                        <el-button type="primary" @click="onCreateGroup">飞机绑定钉钉</el-button>
                        <el-button type="primary" @click="onCreateGroup">批量绑定</el-button>
                        <el-button type="primary" @click="onCreateGroup">批量解绑</el-button>
                        <!-- <el-button type="primary" @click="onDel">删除</el-button> -->
                    </el-form-item>
                </el-form>
            </el-row>
            <el-row>
                <el-table :data="list" v-loading="listLoading" element-loading-text="拼命加载中" border fit
                    highlight-current-row @selection-change="handleSelectionChange">
                    <el-table-column type="selection" width="55" align="center"></el-table-column>
                    <el-table-column prop="telegramToken" label="飞机token" width="255" align="center"></el-table-column>
                    <el-table-column prop="telegramName" label="飞机名称" align="center"></el-table-column>
                    <el-table-column prop="ddHook" label="钉钉token" align="center"></el-table-column>
                    <el-table-column prop="maskWord" label="过滤关键词" align="center"></el-table-column>
                    <el-table-column prop="keyword" label="钉钉推送关键词" align="center"></el-table-column>
                    <el-table-column label="操作" align="center">
                        <template #default="scope">
                            <el-button link type="primary" @click="handleEdit(scope.row)">编辑</el-button>
                            <el-button link type="primary" @click="handleBind(scope.row)">{{ scope.row.state == 1 ? '解绑' : '绑定' }}</el-button>
                            <el-button link type="primary" @click="onDel(scope.row.id)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <!-- 分页 -->
                <div class="pagination">
                    <el-pagination layout="sizes, total, prev, pager, next" :page-sizes="[10, 20, 30]"
                        v-model:page-size="listQuery.rows" v-model:currentPage="listQuery.pageIndex" @current-change="(val) => {
                                fetchData();
                            }
                            " @size-change="(val) => {
                    fetchData();
                }
                " :total="totalRecord"></el-pagination>
                </div>
            </el-row>
        </div>
        <el-dialog title="飞机转钉钉" v-model="dialogGroup" :close-on-click-modal="false" width="600px">
            <el-form-item label="telegramToken" :label-width="120">
                <el-input v-model="groupForm.telegramToken" type="input" placeholder="飞机token" clearable />
            </el-form-item>
            <el-form-item label="telegramName" :label-width="120">
                <el-input v-model="groupForm.telegramName" type="input" placeholder="飞机名称" clearable />
            </el-form-item>
            <el-form-item label="ddHook" :label-width="120">
                <el-input v-model="groupForm.ddHook" type="input" placeholder="钉钉token" clearable />
            </el-form-item>
            <el-form-item label="maskWord" :label-width="120">
                <el-input v-model="groupForm.maskWord" type="input" placeholder="过滤关键词" clearable />
            </el-form-item>
            <el-form-item label="keyword" :label-width="120">
                <el-input v-model="groupForm.keyword" type="input" placeholder="钉钉推送关键词" clearable />
            </el-form-item>
            <el-form-item label="keyword" :label-width="120">
                <el-input v-model="forwardIndex" type="input" placeholder="一键转发" clearable />
            </el-form-item>
            
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="handleForwarod">一键转发{{ forwardIndex }}</el-button>
                    <el-button @click="dialogGroup = false">取 消</el-button>
                    <el-button type="primary" @click="handleSubmitGroup">提交</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>

<script>
import {
    getTelegramDDList,
    telegramDDDel,
    telegramDDGroupAdd,
    telegramDDGroupUpdate,
    telegramDDGroupBind,
    telegramDDGroupUnbind
} from '@/api/telegram';
import { utilsMixin } from '@/mixin/utils';
export default {
    name: 'telegramDD',
    mixins: [utilsMixin],
    data() {
        return {
            forwardIndex: 0,
            dialogGroup: false,
            groupForm: {
                telegramToken: '',
                telegramName: '',
                ddHook: '',
                maskWord: '',
                keyword: '',
            },
            list: [], // 列表数据
            listLoading: true, // 加载状态
            totalRecord: 0, // 数据总条数
            listQuery: {
                pageIndex: 1,
                pageSize: 10,
            },
            listQueryParam: { page: 1 },
        };
    },
    created() {
        this.fetchData();
    },
    methods: {
        batchDeal(isBind) {
            telegramDDGroupBatch({
                bind: isBind,
                maskWord: '',
                keyword: '',
            }).then((res) => {
                if (res.code === 20000) {
                    this.$message({
                        message: '保存成功！',
                        type: 'success',
                    });
                    this.dialogGroup = false;
                    this.fetchData();
                }
            });
        },
        handleForwarod() {
            this.groupForm = {
                id: '',
                telegramToken: '',
                telegramName: '',
                ddHook: '',
                maskWord: '',
                keyword: '',
            };
            switch (this.forwardIndex) {
                case 0:
                    this.groupForm.ddHook = '9d2e9294ba8e38e57676f8e949a4666273fd81ac7e780b9b150cf9cf4d46e4e2';
                    this.groupForm.telegramToken = '7448200184:AAGTGB4YPv-JzOiSI8xX0xPt3U9jyu8umSY';
                    this.groupForm.telegramName = '1号群-邓紫棋';
                    break;
                case 1:
                    this.groupForm.ddHook = '74bcaba856d3e27299babfaf44a05722da4f6016630a6116b0a7ad218916f701';
                    this.groupForm.telegramToken = '7211098027:AAFo3YPVKWUsIuUUvlQxxNoKlZejFqM6MaM';
                    this.groupForm.telegramName = '2号群-张韶涵';
                    break;
                case 2:
                    this.groupForm.ddHook = 'e11e112b7862eaff29096b4e6fbc5c7463daa30cd16ee2fced24bcb056a9e8d3';
                    this.groupForm.telegramToken = '7439174189:AAG4_vn7VQ-9-RhFfVhJPR4Y2y2UdsuxaSc';
                    this.groupForm.telegramName = '3号群-杨幂';
                    break;
                case 3:
                    this.groupForm.ddHook = 'b1aed399d30ebcb22078b377120495b369c927dcf08599cd67d5142d2de45f86';
                    this.groupForm.telegramToken = '7443559207:AAGGZaURSnWoNaGDdYb3NouChc4MIGAeFYI';
                    this.groupForm.telegramName = '4号群-陈乔恩';
                    break;
                case 4:
                    this.groupForm.ddHook = '228405955792705e259f2a1abca301a61fcf64e495ba065712caa6af89e4f44b';
                    this.groupForm.telegramToken = '7454411191:AAG7gXYk8FOGjCzaRPKqiIK5D4Q_38Bs-0A';
                    this.groupForm.telegramName = '5号群-金晨';
                    break;
                case 5:
                    this.groupForm.ddHook = 'c138a7619aa21fddfd11ad9168cd3356ba3fa4ffe415438832397e2bcc0a3e6b';
                    this.groupForm.telegramToken = '6661208075:AAH_opLzzwUKJR9Zp49uDu2_JtZPfGMAVJo';
                    this.groupForm.telegramName = '6号群-章若楠';
                    break;

                case 6:
                    this.groupForm.ddHook = '4237a6e46e2735a3b7f3ce2a746d2e4266dfcbbb6596554f166189b00529d672';
                    this.groupForm.telegramToken = '7978641984:AAFjHbzes4EADS0wq4EDILZbH4pg7OdtRsc';
                    this.groupForm.telegramName = '7号群-孟子义';
                    break;
                case 7:
                    this.groupForm.ddHook = '2bac78f12b5bdc230e90827e581894ac6d4c4015d12eef02aaecf263215c5f0b';
                    this.groupForm.telegramToken = '7911780374:AAFtnLxo_jVpljemG9hFD4_PncmwK-JeSgc';
                    this.groupForm.telegramName = '8号群-虞书欣';
                    break;

                case 8:
                    this.groupForm.ddHook = 'c7a24bb860528be43eeefd2e8c059e76719250dec5ae923c41dcddd371693c78';
                    this.groupForm.telegramToken = '7611787618:AAFUYLdanw34hVs55uyV9DqtP9Ve2ihjzGc';
                    this.groupForm.telegramName = '9号群-李一桐';
                    break;
                
                case 9:
                    this.groupForm.ddHook = '8ab9aedf42b08e101e278360c14fba4cc10e0ae534529d826f5c341f8e5e7225';
                    this.groupForm.telegramToken = '7716130590:AAGq8kLA9qnvbzSkHB6NOgXIZ26vP7paKG8';
                    this.groupForm.telegramName = '10号群-毛晓彤';
                    break;
                case 10:
                    this.groupForm.ddHook = 'e08448deb41287b1167ee965c7b611b11ce55f14e34edb5a85b2387b59b011ce';
                    this.groupForm.telegramToken = '7960559040:AAFV5NsNOtofXu6AIiFdX8GZYgshwkJCszU';
                    this.groupForm.telegramName = '11号群-杨超越';
                    break;
                case 11:
                    this.groupForm.ddHook = 'e22b50cc60de7b553337e7201be671b17c4262c4da76b23f9d1ad6ede5475063';
                    this.groupForm.telegramToken = '7343034263:AAFInl6YLs5pKtPAraZoTxlBjMDrvy2kU8k';
                    this.groupForm.telegramName = '12号群-赵露思';
                    break;
                case 12:
                    this.groupForm.ddHook = '487c88b2b4563968a4b4c2902e9ca64767d3fd96162147165b613834d6bd14f7';
                    this.groupForm.telegramToken = '7222633475:AAFpfCL6FP-Pv3efr6b5_hKLL_ceW6h8UJ0';
                    this.groupForm.telegramName = '13号群-赵丽颖';
                    break;
                case 13:
                    this.groupForm.ddHook = '6b31dd8c33af1d3cd9a3d527c51b7ef6b132e6f52c73d5103996dc6c2277ce62';
                    this.groupForm.telegramToken = '7792086922:AAHt3VmAqsyM7hYRNZo0ocU952eQzTDSEOY';
                    this.groupForm.telegramName = '14号群-高圆圆';
                    break;


                case 14:
                    this.groupForm.ddHook = 'd2e539c50abb344c5015756a3a4b1400f7324703ec72527beeb6dc3cb5e4b088';
                    this.groupForm.telegramToken = '7381424943:AAFKGoypFYFLxXc9k1IbfF2y4yhLfe18yN4';
                    this.groupForm.telegramName = '15号群-张嘉倪';
                    break;
                case 15:
                    this.groupForm.ddHook = '8baf5c74e29038fb2c23fb70e87c711d3d778f6acb3e35aaaa317ca5aebc75bc';
                    this.groupForm.telegramToken = '7786632489:AAHMiG9TD_7HKC_sgZy-bAsa52fvpOjIcI4';
                    this.groupForm.telegramName = '16号群-刘亦菲';
                    break;
                case 16:
                    this.groupForm.ddHook = 'f6ab3f8d2bfc62f44625446c55a0dc680eec6ebb88d6a8137b58ea5a5630f27c';
                    this.groupForm.telegramToken = '7754316327:AAGNjO93zaEZpaWOZPRqwPCyLQRNCb9XIT8';
                    this.groupForm.telegramName = '17号群-江疏影';
                    break;
                case 17:
                    this.groupForm.ddHook = '55ad88a1adc2989b2db1a08e90be5cb6b8ba1005ba024adbaac1fe565991ab41';
                    this.groupForm.telegramToken = '7668299693:AAE67uNwYEo6Who-E0XAMQOz3dwK0KlBZ68';
                    this.groupForm.telegramName = '18号群-汤唯';
                    break;
                case 18:
                    this.groupForm.ddHook = '6913cf185feb750769bc86b07b690c7e7d3b8fd7e60d2a2c744141ace0075c5b';
                    this.groupForm.telegramToken = '7602786160:AAG4Q8IJcMdK9eesegcy9KROsaw-KG8wHsk';
                    this.groupForm.telegramName = '19号群-蔡依林';
                    break;
                case 19:
                    this.groupForm.ddHook = 'e4b1a1769effff890fcfce6027ffb224b9b52de41eaf04afc54488f6b55a5511';
                    this.groupForm.telegramToken = '7887271175:AAEEpCS-fM5-xMiymw2vl5wdEvf8y5qG8jE';
                    this.groupForm.telegramName = '20号群-王心凌';
                    break;
                case 20:
                    this.groupForm.ddHook = '4b4dcef1c2f9969c2dfc8417ae3ef8a7656860408774d2752c39525cc7909d42';
                    this.groupForm.telegramToken = '7623970024:AAGUtlKXhJWoMqf-ii6T5LsOKsG4oh4-YiM';
                    this.groupForm.telegramName = '21号群-郭美美';
                    break;
                case 21:
                    this.groupForm.ddHook = '56de6d66ad809fbf934f52f1534f65ba7ffe2f2b68736a338439f81c6a9220b2';
                    this.groupForm.telegramToken = '8171086470:AAE6un0l0bRKBfaU3HfOns2MiYin-cQyaNs';
                    this.groupForm.telegramName = '22号群-朱丽清';
                    break;
                case 22:
                    this.groupForm.ddHook = '8a88978b48d6ff01eb575d8f462848d4646eb912b549639a2beb454fccb01ad7';
                    this.groupForm.telegramToken = '7695421318:AAE4mEeTA_Ov5Vc2qMpCJ9BQSgs4txTQZzs';
                    this.groupForm.telegramName = '23号群-景甜';
                    break;
                case 23:
                    this.groupForm.ddHook = '0794a169858ca70d7133303e4168fe45f5567a90b7fac48d8b9dc67fab9ee99e';
                    this.groupForm.telegramToken = '7566892881:AAEFR7-Da0WJpjDM_5EWYOG2hS0Sp9MbxgE';
                    this.groupForm.telegramName = '24号群-BABY-';
                    break;
                case 24:
                    this.groupForm.ddHook = '6b18c52ac7dd2e772f829de198b555fb04a68e07e98bd711530136182e7001e9';
                    this.groupForm.telegramToken = '7385269685:AAFQb6gNA1e_G_pNNbK0MSueSkq2rpkM_u4';
                    this.groupForm.telegramName = '25号群-范冰冰';
                    break;
                case 25:
                    this.groupForm.ddHook = 'c5c2a824f22cd8e1917c81035c721cd33a90f2fae80a2938aa9dac96cb6b28a0';
                    this.groupForm.telegramToken = '7668333040:AAEldlMY9Fhe-c-sz_qJI8hCu4hkTyXB-wA';
                    this.groupForm.telegramName = '26号群-古力娜扎';
                    break;
                case 26:
                    this.groupForm.ddHook = '99ed25f1e03630d0c52408d0c350bd6a9203a12cf79fd4b3f5f48a58cab0ef5d';
                    this.groupForm.telegramToken = '7742640016:AAHkTHyb0e9li1XzxkpLncHqAe0OtAeMJ6k';
                    this.groupForm.telegramName = '27号群-刘诗诗';
                    break;
                // case 27:
                //     this.groupForm.ddHook = 'd731ad691826291d753a3dacd655ff4f09c43eb9a10af39a80a3ba2d5bc7563c';
                //     this.groupForm.telegramToken =
                //     this.groupForm.telegramName = '28号群-杨紫';
                //     break;
                // case 28:
                //     this.groupForm.ddHook = '6831390d0cead8f4b081bc44d1a9c18dd2a45bb212a90ae0bba66bb5afccd631';
                //     this.groupForm.telegramToken =
                //     this.groupForm.telegramName = '29号群-谢娜';
                //     break;

                    
            }
            this.forwardIndex = Number(this.forwardIndex) + 1;
            
        },
        handleSubmitGroup() {
            const { telegramToken, telegramName, ddHook, maskWord, keyword } = this.groupForm;
            if (!this.groupForm.id) {
                telegramDDGroupAdd({
                    telegramToken,
                    telegramName,
                    ddHook,
                    maskWord,
                    keyword,
                }).then((res) => {
                    if (res.code === 20000) {
                        this.$message({
                            message: '保存成功！',
                            type: 'success',
                        });
                        this.dialogGroup = false;
                        this.fetchData();
                    }
                });
            } else {
                telegramDDGroupUpdate(this.groupForm).then((res) => {
                    if (res.code === 20000) {
                        this.$message({
                            message: '更新成功！',
                            type: 'success',
                        });
                        this.dialogGroup = false;
                        this.fetchData();
                    }
                });
            }
        },
        onCreateGroup() {
            this.groupForm = {
                id: '',
                telegramToken: '',
                telegramName: '',
                ddHook: '',
                maskWord: '',
                keyword: '',
            };
            this.dialogGroup = true;
        },
        fetchData() {
            this.listLoading = true;
            getTelegramDDList(this.listQuery)
                .then((res) => {
                    if (res.code === 20000) {
                        this.list = res.data.records;
                        this.totalRecord = res.data.total;
                    }
                    this.listLoading = false;
                })
                .catch(() => {
                    this.listLoading = false;
                });
        },
        handleSelectionChange(value) {
            this.selectList = value;
            console.log('====', this.selectList);
        },
        onDel(id) {
            telegramDDDel({ id }).then((res) => {
                this.$message({ message: '删除成功', type: 'success' });
                this.fetchData();
            });
        },
        // 查询
        onSearch() {
            // this.listQuery = Object.assign(this.listQuery, this.listQueryParam); // 合并对象
            this.fetchData();
        },
        handleBind(row) {
            if (row.state === 1) {
                telegramDDGroupUnbind({
                    id: row.id, 
                }).then((res) => {
                    if (res.code === 20000) {
                        this.$message({
                            message: '解绑成功！',
                            type: 'success',
                        });
                        this.fetchData();
                    }
                });
            } else {
                telegramDDGroupBind({
                    id: row.id, 
                }).then((res) => {
                    if (res.code === 20000) {
                        this.$message({
                            message: '绑定成功！',
                            type: 'success',
                        });
                        this.fetchData();
                    }
                });
            }
            
        },
        // 编辑
        handleEdit(row) {
            this.groupForm = {
                id: row.id,
                telegramToken: row.telegramToken,
                telegramName: row.telegramName,
                ddHook: row.ddHook,
                maskWord: row.maskWord,
                keyword: row.keyword,
            };
            this.dialogGroup = true;
        },
    },
};
</script>
